package com.gary.springcloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.sun.deploy.security.BlockedException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author peng_rui
 * @date 2022/7/12
 */
@Slf4j
@RestController
public class HelloController {

    @RequestMapping(value = "/testA", method = RequestMethod.GET)
    public String testA() throws InterruptedException {
        Thread.sleep(1000);
        log.info("testA...");
        return "testA....";
    }

    @RequestMapping(value = "/testB", method = RequestMethod.GET)
    public String testB() {
        log.info("testB...");
        return "testB....";
    }

    @RequestMapping(value = "/testE", method = RequestMethod.GET)
    public String testE() {
        log.info("testE...");
        int a = 10 / 0;
        return "testE....";
    }

    @SentinelResource(value = "testHotKey", blockHandler = "deal_testHotKey")
    @RequestMapping(value = "/testHotKey", method = RequestMethod.GET)
    public String testHotKey(@RequestParam(value = "p1", required = false) String p1,
                             @RequestParam(value = "p2", required = false) String p2) {
        log.info("testHotKey...");
        return "testHotKey....";
    }

    public String deal_testHotKey(String p1, String p2, BlockException e) {
        return "testHotKey.... /(ㄒoㄒ)/~~";
    }
}
